package com.TaskOrganizer.gui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import com.TaskOrganizer.dialogs.ListTasksDialog;
import com.TaskOrganizer.dialogs.TaskDialog;
import com.TaskOrganizer.managers.TaskPriority;
import com.TaskOrganizer.task.Task;

public class TaskButton extends JButton {

	private static final long serialVersionUID = -2818703916087140690L;
	public Task task;
	public ListTasksDialog owner;

	public TaskButton(Task task, ListTasksDialog owner) {
		super(task.getName());
		this.setTask(task);
		this.owner = owner;
		if (task.getPriority().equals(TaskPriority.HIGH)) {
			setBackground(Color.RED);
		} else {
			setBackground(Color.GREEN);
		}
		this.setOpaque(true);
		addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				getOwner().dispose();
				new TaskDialog(getTask());
			}

		});
	}

	public Task getTask() {
		return task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public ListTasksDialog getOwner() {
		return owner;
	}

	public void setOwner(ListTasksDialog owner) {
		this.owner = owner;
	}

}
